var api=require("api");
var util=require("../utils/util");

// 查询宝宝购买课程列表
function get_baby_cour(params,token) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.getBabyCour,
      header: {
        'content-type': 'application/json;charset=UTF-8',
        'x-access-token': token
      },
      method: 'GET',
      data: params,
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}
// 查询课表
function get_cour_table(params,token) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.getCourTable,
      header: {
        'content-type': 'application/json;charset=UTF-8',
        'x-access-token': token
      },
      method: 'GET',
      data: params,
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}
// 添加评论
function add_comment(params,token) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.addCourComment,
      header: {
        'content-type': 'application/json;charset=UTF-8',
        'x-access-token': token
      },
      method: 'POST',
      data: params,
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}
// 请假
function user_set_leave(params,token) {
  return new Promise((resolve,reject)=>{
    wx.request({
      url: api.data.requestUrl + api.data.userSetLeave,
      header: {
        'content-type': 'application/json;charset=UTF-8',
        'x-access-token': token
      },
      method: 'POST',
      data: params,
      success: function (res) {
        resolve(res);
        util.show_success_toast(res)
      },
      fail: function () {
        reject();
        util.show_fail_toast()
      },
    })
  })
}

module.exports={
  get_baby_cour,
  get_cour_table,
  add_comment,
  user_set_leave
}